package com.jyh.homework.t4;

import java.io.*;

/**
 * @Author JYH
 * @Date 2024/8/6 18:41
 * @Description 1、声明一个Message类，包含：发送者、接收者、消息内容、发送时间
                2、创建一个Message对象，并写到message.dat文件中，并再次读取显示
 */
public class test4 {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("D:\\Study\\JavaSE-plus\\JavaSE-code\\day10-code\\src\\com\\jyh\\homework\\t4\\message.dat"));
        ObjectOutputStream oos = new ObjectOutputStream(bos);
        oos.writeObject(new Message("蔡徐坤","王子异","哇!真的是你呀!哎呀!","2024-08-06"));
        oos.close();

        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("D:\\Study\\JavaSE-plus\\JavaSE-code\\day10-code\\src\\com\\jyh\\homework\\t4\\message.dat"));
        ObjectInputStream ois = new ObjectInputStream(bis);
        Message message1 = (Message) ois.readObject();
        System.out.println(
                "发送者:"+message1.getFaName()+"\n接收者:"+message1.getShouName()+"\n消息内容:"+message1.getMessage()+"\n发送时间:"+message1.getTime()
        );
        ois.close();
    }
}
